#ifndef _ETF_H_
#define _ETF_H_

#include "imatrix.h"

struct Vect {
	double tx, ty, mag;
};


class ETF {
private:
	int m_iHeight;
	int m_iWidth;
	Vect** p; 
	double max_grad;
public:
	ETF() 
    {
		m_iHeight = 1;
		m_iWidth = 1;
		p = new Vect*[m_iHeight];
		for(int i = 0; i < m_iHeight; i++)
		   p[i] = new Vect[m_iWidth];
        p[0][0].tx=1.0; p[0][0].ty=0.0; p[0][0].mag=1.0;
        max_grad = 1.0;
    };
	ETF(int i, int j) 
    {
		m_iHeight = i, m_iWidth = j;
		p = new Vect*[m_iHeight];
		for(i = 0; i < m_iHeight; i++)
		   p[i] = new Vect[m_iWidth];
		max_grad = 1.0;
    };
	void delete_all() {
		for (int i = 0; i < m_iHeight; i++) 
			delete[] p[i];
		delete[] p;
	}
	~ETF() { delete_all(); }
	Vect* operator[](int i) { return p[i]; };
	Vect& get( int i, int j ) const { return p[i][j]; }
	int getRow() const { return m_iHeight; }
	int getCol() const { return m_iWidth; }
	void init(int i, int j);
	void copy(ETF& s);
	void zero();
	void set(imatrix& image);	// from input image
	void set2(imatrix& image);	// from gradient map
	void Smooth(int half_w, int M);
	double GetMaxGrad() { return max_grad; }
	void normalize(); 

	void SavePPM(const char* pszFileName);
	void SavePPM(const imatrix& org, const char* pszFileName);
	void ApplyDepth(const char* pszFilename);
	void SmoothWithDepth(int half_w, int M, const char* pszFilename);
};


#endif